<html>
<head><meta charset="utf-8"><title>Why not something like nth but consume the iterator? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20not.20something.20like.20nth.20but.20consume.20the.20iterator.3F.html">Why not something like nth but consume the iterator?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208484433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Why%20not%20something%20like%20nth%20but%20consume%20the%20iterator%3F/near/208484433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanif Ariffin <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20not.20something.20like.20nth.20but.20consume.20the.20iterator.3F.html#208484433">(Aug 30 2020 at 13:05)</a>:</h4>
<p>To me, its kinda weird that iterator have <code>last()</code> but not <code>first()</code>. While we are at it, why not something like <code>kth()</code>. This is useful when you are doing something like finding the middle point or something like that, you sort an iterator, then return the <code>kth(len / 2)</code>. This way, we can make <code>last()</code> and <code>first()</code> a specialization of <code>kt()</code>.</p>



<a name="208484499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Why%20not%20something%20like%20nth%20but%20consume%20the%20iterator%3F/near/208484499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20not.20something.20like.20nth.20but.20consume.20the.20iterator.3F.html#208484499">(Aug 30 2020 at 13:06)</a>:</h4>
<p>(I think this is the wrong channel, can someone move this to <a class="stream" data-stream-id="122651" href="/#narrow/stream/122651-general">#general</a> or so? <a class="stream" data-stream-id="213817" href="/#narrow/stream/213817-t-lang">#t-lang</a> is for language design, not library questions.)<br>
<span class="user-mention" data-user-id="242691">@Hanif Ariffin</span> there's <a href="https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.nth"><code>nth</code></a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>